// Forward Compositor
// (c) jimon game studio

#ifndef JEH_CFORWARDCOMPOSITOR
#define JEH_CFORWARDCOMPOSITOR

#include "ICompositor.h"
#include "IRender.h"

namespace je
{
	namespace scene
	{
		//! Forward Compositor
		class CForwardCompositor:public je::scene::ICompositor
		{
		protected:
			//! Max Lights Per Pass
			u32 MaxLightsPerPass;

			//! Light Position for solid objects
			video::IShaderGlobalVariable * Solid_LightPosition;

			//! Light Position count for solid objects
			video::IShaderGlobalVariable * Solid_LightPosition_Count;

			//! Light Position for transparent objects
			video::IShaderGlobalVariable * Transparent_LightPosition;

			//! Light Position count for transparent objects
			video::IShaderGlobalVariable * Transparent_LightPosition_Count;

			//! Light Position for transparent objects setup callback
			class CTransparentLightPositionSetupCallback:public je::video::IPreRenderOperationCallback
			{
			public:
				//! Light Positions Array Type
				typedef jeDynamicArray<jeVector3df> LightPositionsArrayType;
			protected:
				//! Current variable
				video::IShaderVariable * CurrentTransparentLightPosition;

				//! Current variable
				video::IShaderVariable * CurrentTransparentLightPositionCount;

				//! Current light positions
				LightPositionsArrayType * CurrentLightPositions;
			public:
				//! Constructor
				CTransparentLightPositionSetupCallback(video::IShaderVariable * Transparent_LightPosition,video::IShaderVariable * Transparent_LightPositionCount)
					:CurrentTransparentLightPosition(Transparent_LightPosition),CurrentTransparentLightPositionCount(Transparent_LightPositionCount)
				{
				}

				//! Destructor
				~CTransparentLightPositionSetupCallback()
				{
				}

				//! On Render Operation
				void OnRenderOperation(video::RenderOperationType Type,video::jeRenderOperation * Data)
				{
					CurrentTransparentLightPosition->SetVector(CurrentLightPositions->GetPtr(),CurrentLightPositions->GetSize());
					CurrentTransparentLightPositionCount->Sets32(CurrentLightPositions->GetSize());
					IPreRenderOperationCallback::OnRenderOperation(Type,Data);
				}

				//! Set Light Positions
				void SetLightPositions(LightPositionsArrayType * LightPositions)
				{
					CurrentLightPositions = LightPositions;
				}
			};

			//! Setup callback
			CTransparentLightPositionSetupCallback * CurrentCallback;
		public:
			//! Constructor
			CForwardCompositor(ISceneManager * SceneManager);

			//! Destructor
			~CForwardCompositor();

			//! On Render
			void OnRender();

			//! Serialize
			void Serialize(core::ISerializeStream * SerializeStream);

			//! Get Compositor Type Name
			jeStringc GetCompositorTypeName()
			{
				return "ForwardCompositor";
			}
		};
	}
}

#endif
